#include "LQ_TFT18.h"

unsigned short blue = 0x001f;
unsigned short white = 0xffff;

/*
 * @brief 显示横晶体管样式线
 *
 * @param   x:起始x
 * @param   y:起始y
 * @param   color:颜色RGB565
 */
void transverseLine(int x,int y,unsigned short color){
    TFTSPI_Draw_Part(x+3,y+0,x+18,y+0,color);
    TFTSPI_Draw_Part(x+3,y+6,x+18,y+6,color);
    TFTSPI_Draw_Part(x+2,y+1,x+19,y+1,color);
    TFTSPI_Draw_Part(x+2,y+5,x+19,y+5,color);
    TFTSPI_Draw_Part(x+1,y+2,x+20,y+2,color);
    TFTSPI_Draw_Part(x+1,y+4,x+20,y+4,color);
    TFTSPI_Draw_Part(x+0,y+3,x+21,y+3,color);
}
/*
 * @brief 显示竖晶体管样式线
 *
 * @param   x:起始x
 * @param   y:起始y
 * @param   color:颜色RGB565
 */
void verticalLine(int x,int y,unsigned short color){
    TFTSPI_Draw_Part(x+0,y+3,x+0,y+18,color);
    TFTSPI_Draw_Part(x+6,y+3,x+6,y+18,color);
    TFTSPI_Draw_Part(x+1,y+2,x+1,y+19,color);
    TFTSPI_Draw_Part(x+5,y+2,x+5,y+19,color);
    TFTSPI_Draw_Part(x+2,y+1,x+2,y+20,color);
    TFTSPI_Draw_Part(x+4,y+1,x+4,y+20,color);
    TFTSPI_Draw_Part(x+3,y+0,x+3,y+21,color);
}

void aLine(int x,int y,unsigned short color){
    transverseLine(x+5,y,color);
}
void bLine(int x,int y,unsigned short color){
    verticalLine(x+25,y+4,color);
}
void cLine(int x,int y,unsigned short color){
    verticalLine(x+25,y+27,color);
}
void dLine(int x,int y,unsigned short color){
    transverseLine(x+5,y+46,color);
}
void eLine(int x,int y,unsigned short color){
    verticalLine(x,y+27,color);
}
void fLine(int x,int y,unsigned short color){
    verticalLine(x,y+4,color);
}
void gLine(int x,int y,unsigned short color){
    transverseLine(x+5,y+23,color);
}

//pixel 32*53
/*
 * @brief 显示对应的晶体管样式数字
 */
void displayChar0(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,white);
    fLine(x,y,white);
    gLine(x,y,blue);
}
void displayChar1(int x,int y){
    aLine(x,y,blue);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,blue);
    eLine(x,y,blue);
    fLine(x,y,blue);
    gLine(x,y,blue);
}
void displayChar2(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,blue);
    dLine(x,y,white);
    eLine(x,y,white);
    fLine(x,y,blue);
    gLine(x,y,white);
}
void displayChar3(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,blue);
    fLine(x,y,blue);
    gLine(x,y,white);
}
void displayChar4(int x,int y){
    aLine(x,y,blue);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,blue);
    eLine(x,y,blue);
    fLine(x,y,white);
    gLine(x,y,white);
}
void displayChar5(int x,int y){
    aLine(x,y,white);
    bLine(x,y,blue);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,blue);
    fLine(x,y,white);
    gLine(x,y,white);
}
void displayChar6(int x,int y){
    aLine(x,y,white);
    bLine(x,y,blue);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,white);
    fLine(x,y,white);
    gLine(x,y,white);
}
void displayChar7(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,blue);
    eLine(x,y,blue);
    fLine(x,y,blue);
    gLine(x,y,blue);
}
void displayChar8(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,white);
    fLine(x,y,white);
    gLine(x,y,white);
}
void displayChar9(int x,int y){
    aLine(x,y,white);
    bLine(x,y,white);
    cLine(x,y,white);
    dLine(x,y,white);
    eLine(x,y,blue);
    fLine(x,y,white);
    gLine(x,y,white);
}
/*
 * @brief 显示对应的晶体管样式冒号
 *
 * @param   x:起始x
 * @param   y:起始y
 * @param   status：冒号显示的状态
 */
void displayPoint(int x,int y,int status){
    if(status){
        TFTSPI_Draw_Part(x+5,y+16,x+12,y+23,white);
        TFTSPI_Draw_Part(x+5,y+30,x+12,y+37,white);
    }
    else{
        TFTSPI_Draw_Part(x+5,y+16,x+12,y+23,blue);
        TFTSPI_Draw_Part(x+5,y+30,x+12,y+37,blue);
    }
}
/*
 * @brief 根据输入的数字选择显示对应的晶体管样式字
 *
 * @param   x:起始x
 * @param   y:起始y
 * @param   displayNumber：显示的数字
 *
 */
void displayByNumber(int x,int y,int displayNumber){
    switch(displayNumber){
        case 0:
            displayChar0(x,y);
            break;
        case 1:
            displayChar1(x,y);
            break;
        case 2:
            displayChar2(x,y);
            break;
        case 3:
            displayChar3(x,y);
            break;
        case 4:
            displayChar4(x,y);
            break;
        case 5:
            displayChar5(x,y);
            break;
        case 6:
            displayChar6(x,y);
            break;
        case 7:
            displayChar7(x,y);
            break;
        case 8:
            displayChar8(x,y);
            break;
        case 9:
            displayChar9(x,y);
            break;
    }
}
